﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace CommonLib
{
	public class QuadTreeNodeHolder : LazySingleton<QuadTreeNodeHolder>
	{
		protected Dictionary<int, QuadTreeNode> dicNodes;
		public int Count => dicNodes.Count;


		protected QuadTreeNodeHolder() {
			dicNodes = new Dictionary<int, QuadTreeNode>();
		}
		public void AddNode(QuadTreeNode treeNode)
		{
			if (!dicNodes.ContainsKey(treeNode.InstanceId))
			{
				dicNodes.Add(treeNode.InstanceId, treeNode);
			}
		}
		public void RemoveNode(QuadTreeNode treeNode)
		{
			if (dicNodes.ContainsKey(treeNode.InstanceId))
			{
				dicNodes.Remove(treeNode.InstanceId);
			}
		}
		public QuadTreeNode GetNode(int key)
		{
			if(dicNodes.TryGetValue(key ,out QuadTreeNode node))
			{
				return node;
			}
			else
			{
				return null;
			}
		}
	}
}